home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / glisp / glisp.000 / GLISP.UNIX.TAR / closunix / closlex.l < prev    next >
Encoding:
Lex Description  |  1995-04-03  |  2.4 KB  |  122 lines

  1. %{
  2. /*                 GRAPHIC LISP            */
  3. /*        Scritto nel 1991-94 da Zoia Andrea Michele     */
  4. /*        Via Pergola #1 Tirano (SO) Tel. 0342-704210    */
  5. /* file closlex.l */
  6. #define CLOSLEX_L
  7. #include "clos.h"
  8. #include "closyacc.h"
  9.  
  10. #undef  input
  11. #define input() \
  12. (\
  13.     (\
  14.     ( yytchar=yysptr>yysbuf\
  15.           ?U(*--yysptr)\
  16.           :lisp_get_char(yacc_filein)\
  17.     )==10\
  18.         ?(yylineno++,yytchar)\
  19.         :yytchar\
  20.     )==EOF\
  21.     ?0\
  22.     :yytchar\
  23. )
  24.  
  25. int        sq_b_fl=FALSE;
  26. int        parcount=0;
  27. extern FILE    *yacc_filein;
  28.  
  29. %}
  30. integer        [+-]?[0-9]+
  31. real1        [+-]?[0-9]*"."[0-9]+
  32. real2        [+-]?[0-9]*"."[0-9]+[Ee][+-]?[0-9]+
  33. real3        [+-]?[0-9]+[Ee][+-]?[0-9]+
  34. real        {real1}|{real2}|{real3}
  35. identifier    [^ \n\t\"\;\.\,\'\#\&\:\~\]\(\)]+
  36. rem        ";"[^\n]*\n
  37. string        \"("\\\""|[^\"\n])*[\"\n]
  38. nl        \n
  39. legalchar    "."|","|"'"|"#"|":"|"&"|"~"
  40. openpar        (
  41. closepar    )
  42. squarepar    ]
  43. nothing        [ \t]+
  44.  
  45. %%
  46.  {
  47.   if(sq_b_fl){
  48.    if(parcount){
  49.       parcount--;
  50.       return ')';
  51.    }
  52.    sq_b_fl=FALSE;
  53.   }
  54.  }
  55. {nothing}    ;
  56. {legalchar}    {return yytext[0];}
  57. {nl}|{rem}    {return '\n';}
  58. "("        {parcount++;return '(';}
  59. ")"        {parcount--;return ')';}
  60. "]"        {
  61.             if(!parcount){
  62.                 return BAD_SQB_YY;
  63.             }
  64.             else{
  65.                 sq_b_fl=TRUE;
  66.                 parcount--;
  67.                 return ')';
  68.             }
  69.         }
  70. {integer}    {
  71.             sscanf(yytext,"%ld",&yylval.integer);
  72.             return    INTEGER_YY;
  73.         }
  74. {real}        {
  75.             sscanf(yytext,"%lf",&yylval.real);
  76.             return REAL_YY;
  77.         }
  78. {identifier}    {
  79.             yylval.ident=yytext;
  80.             if(!config.case_sensitive)
  81.             {  /* converte le lettere in upper-case */
  82.                /* es 'anDRea23*ee'-->'ANDREA23*EE' */
  83.                 while(*yylval.ident){
  84.                 if(*yylval.ident>='a' && *yylval.ident<='z')
  85.                     *yylval.ident=*yylval.ident-('a'-'A');
  86.                 yylval.ident++;
  87.                 }
  88.                 yylval.ident=yytext;
  89.             }
  90.             if(strlen(yytext)>config.max_id_lenght){
  91.                 yytext[config.max_id_lenght]=0;
  92.                 error(E_IDLONG,ERR_MWARN|ERR_TNORM|ERR_PSTRING,
  93.                 yytext);
  94.             }
  95.             return    IDENTIFIER_YY;
  96.         }
  97. {string}    {
  98.             if(yytext[strlen(yytext)-1]!='"')
  99.                 return BAD_STRING_YY;
  100.             if(strlen(yytext)>config.max_string_lenght+2){
  101.                 yytext[config.max_string_lenght+1]=0;
  102.                 error(E_STRLONG,ERR_MWARN|ERR_TNORM|ERR_PSTRING,
  103.                    &yytext[1]);
  104.             }else{
  105.                 yytext[strlen(yytext)-1]=0;
  106.             }
  107.             yylval.ident=&yytext[1];
  108.             return    STRING_YY;
  109.         }
  110. .        {
  111.             if(config.bad_char_error){
  112.             yylval.integer=(n_int)yytext[0];
  113.             return BAD_CHAR_YY;
  114.             }
  115.             else{
  116.             sprintf(buf1,"Char '%c' ascii %i",yytext[0],yytext[0]);
  117.             error(E_BADCH,ERR_MWARN|ERR_PSTRING|ERR_TNORM,buf1);
  118.             }
  119.         }
  120. %%
  121.  
  122.